package com.frank.jpaBatchSave.repository;

import com.frank.jpaBatchSave.entity.Person;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface PersonRepository extends PagingAndSortingRepository<Person, Integer> {

//    https://blog.csdn.net/zccbbg/article/details/84170868
    @Query("select distinct new Person(p.name, p.province, p.city) from Person p")
    List<Person> getAllPerson();

    @Query("select min(age) from Person where age > 0")
    Optional<Integer> findMinAge();

    Optional<Person> deleteById(int id);

}
